import json
import re
import sys
import time
from random import random

import requests
from bs4 import BeautifulSoup
import csv


import json

from gainian.get_gainian import get_gainian_code_name
from gainian.one_gainian import get_one_gianian

def radom_sleep(a=3, b=2):
    import time
    import random
    time.sleep(random.random() * a + b)


code, name = get_gainian_code_name()
print(code, name)


with open("res_2.json",'r', encoding='utf-8') as load_f:
    load_dict = json.load(load_f)

map = load_dict

for i in range(len(code)):
    if i <= 234:
        continue
    code_list = get_one_gianian(code[i])
    gainian_name = name[i]
    for cc_l in code_list:
        if cc_l in map.keys():
            res = map[cc_l]
            res.append(gainian_name)
            map[cc_l] = res
        else:
            res = []
            res.append(gainian_name)
            map[cc_l] = res

    print(i, code[i], gainian_name)
    print(map)
    jsObj = json.dumps(map)
    fileObject = open(r'res.json', 'w', encoding='utf-8')
    fileObject.write(jsObj)
    fileObject.close()
    radom_sleep()
    print()